package com.hfzy.ihk.web.calldata.biz;

import com.alibaba.fastjson.JSON;
import com.hfzy.ihk.common.constants.GlobalStatic;
import com.hfzy.ihk.common.core.elasticsearch.ElasticsearchOperation;
import com.hfzy.ihk.common.core.elasticsearch.service.EsBaseServiceImpl;
import com.hfzy.ihk.common.facade.enums.CustomerNeedLevel;
import com.hfzy.ihk.common.util.string.StringTools;
import com.hfzy.ihk.common.web.WebResult;
import com.hfzy.ihk.facade.calldata.entity.CallHistoryText;
import com.hfzy.ihk.facade.calldata.entity.CallTaskDetail;
import com.hfzy.ihk.facade.calldata.enums.CallDataOperations;
import com.hfzy.ihk.facade.calldata.enums.CallDataRedisVersionKey;
import com.hfzy.ihk.facade.calldata.enums.CallDataTables;
import com.hfzy.ihk.web.calldata.constant.RedisKey;
import com.hfzy.ihk.web.calldata.dao.CallTaskDetailRepository;
import com.hfzy.ihk.web.calldata.handlers.CallTaskDetailTableOperationHandler;
import com.hfzy.ihk.web.calldata.serviceImpl.EsOptRmiServiceImpl;
import com.hfzy.ihk.web.calldata.vo.CallTaskDetailTotalVo;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.search.sort.FieldSortBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
import org.springframework.data.elasticsearch.core.query.SourceFilter;
import org.springframework.data.elasticsearch.repository.ElasticsearchCrudRepository;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.text.NumberFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.LinkedBlockingQueue;

/**
 * Created by Administrator on 2018/8/24.
 */
@Component
public class CallTaskDetailBiz extends EsBaseServiceImpl<CallTaskDetail>{

    private static final Logger logger = LoggerFactory.getLogger(CallTaskDetailBiz.class);

    @Autowired
    CallTaskDetailRepository callTaskDetailRepository;

    @Autowired
    RedisTemplate redisTemplate;

    @Autowired
    CallTaskDetailTableOperationHandler callTaskDetailTableOperationHandler;

    private static ConcurrentHashMap<String,LinkedBlockingQueue<Runnable>> instanceMap = new ConcurrentHashMap<String, LinkedBlockingQueue<Runnable>>();

    public void queueStatisticsCallHistory(Map<String,Object> redisMap) throws Exception {
        instanceMap.putIfAbsent(redisMap.get("callTaskId").toString(),new LinkedBlockingQueue());
        instanceMap.get(redisMap.get("callTaskId").toString()).put(new CallQueue(redisMap));
        Thread thread = new Thread(instanceMap.get(redisMap.get("callTaskId").toString()).take());
        thread.start();
    }

     class CallQueue implements Runnable{

        private Map<String,Object> redisMap;

        public CallQueue(Map<String,Object> redisMap){
            this.redisMap = redisMap;
        }

        @Override
        public void run() {
            try {
                statisticsCallHistory(redisMap);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    }

    @Override
    protected ElasticsearchCrudRepository getReposity() {
        return callTaskDetailRepository;
    }

    /**
     * 新增呼叫任务详情
     * @param callTaskDetail
     * @return
     */
    public WebResult saveCallTaskDetail(CallTaskDetail callTaskDetail){
        WebResult result = new WebResult();
        boolean flag = createDataAndSetVersion(CallDataRedisVersionKey.TABLE_CALL_TASK_DETAIL,
                CallDataTables.CALL_TASK_DETAIL,
                callTaskDetail.getCallTaskId(),
                callTaskDetail.getVersion(),
                ()-> callTaskDetailRepository.save(callTaskDetail));

        if(!flag){
            result.setCode(GlobalStatic.CODE_N);
            result.setMsg("保存出错");
            return result;
        }

        result.setCode(GlobalStatic.CODE_1);
        result.setMsg("成功");

        return result;
    }

    /**
     * 修改呼叫任务详情
     * @param updateMap
     * @param callTaskDetailId
     * @param version
     * @return
     */
    public WebResult updateCallTaskDetail(Map<String,Object> updateMap, String callTaskDetailId, Long version){
        WebResult result = new WebResult();
        updateMap.put("version",version + 1);
        boolean flag = checkVersionAndUpdateData(CallDataRedisVersionKey.TABLE_CALL_TASK_DETAIL,
                CallDataTables.CALL_TASK_DETAIL,
                callTaskDetailId,
                version,
                ()-> callTaskDetailRepository.updateSomeFields(callTaskDetailId,CallHistoryText.class,updateMap));

        if(!flag){
            result.setCode(GlobalStatic.CODE_N);
            result.setMsg("保存出错");
            return result;
        }

        result.setCode(GlobalStatic.CODE_1);
        result.setMsg("成功");

        return result;
    }

    /**
     * 分页查询通话记录
     * @param boolQueryBuilder
     * @param sort
     * @param pageable
     * @return
     * @throws Exception
     */
    public Page<CallTaskDetail> queryCallTaskDetailPageList(BoolQueryBuilder boolQueryBuilder, FieldSortBuilder sort, Pageable pageable, SourceFilter sourceFilter)throws Exception{
        if(pageable == null){
            pageable = PageRequest.of(0,10);
        }
        NativeSearchQueryBuilder builder = new NativeSearchQueryBuilder().withPageable(pageable);
        if(boolQueryBuilder !=null && boolQueryBuilder.hasClauses()){
            builder.withQuery(boolQueryBuilder);
        }
        if(sort != null){
            builder.withSort(sort);
        }
        if(sourceFilter!=null){
            builder.withSourceFilter(sourceFilter);
        }
        Page<CallTaskDetail> page = callTaskDetailRepository.search(builder.build());
        return page;
    }

    /**
     * 统计呼叫任务详情放到redis
     * @param paramMap
     */
    public void statisticsCallHistory(Map<String,Object> paramMap)throws Exception{
        logger.info("统计呼叫任务详情放到redis paramMap:{}",JSON.toJSONString(paramMap));
        if(paramMap!=null&&!paramMap.isEmpty()&&paramMap.containsKey("callTaskId")){
            Object json = redisTemplate.opsForHash().get(RedisKey.CALL_TASK,paramMap.get("callTaskId").toString());
            CallTaskDetailTotalVo callTaskDetailTotalVo = new CallTaskDetailTotalVo();
            if(StringTools.isNotempty(json)){
                callTaskDetailTotalVo = JSON.toJavaObject(JSON.parseObject(json.toString()),CallTaskDetailTotalVo.class);
            }else{
                callTaskDetailTotalVo.setCallTaskId(paramMap.get("callTaskId").toString());
            }
            /*int callSize = callTaskDetailTotalVo.getSize();//任务包总数
            if(callSize==0){//不存在时去查询

            }*/

            NumberFormat numberFormat = NumberFormat.getInstance();
            numberFormat.setMaximumFractionDigits(0);

            int progressTotal = callTaskDetailTotalVo.getProgressTotal();//以拨打的总数
            if(paramMap.containsKey("sessionId")){
                progressTotal += 1;
                callTaskDetailTotalVo.setProgressTotal(progressTotal);
                callTaskDetailTotalVo.setProgress(progressTotal);
                /*if(callSize!=0){
                    //电话拨打进度%
                    callTaskDetailTotalVo.setProgress(Integer.parseInt(numberFormat.format(((float)progressTotal/(float)callSize*100))));
                }*/
            }
            int connectedTimes = callTaskDetailTotalVo.getConnectedTimes();
            if(paramMap.containsKey("callState")){//电话接通次数
                if(Boolean.valueOf(paramMap.get("callState").toString())){
                    connectedTimes += 1;
                    callTaskDetailTotalVo.setConnectedTimes(connectedTimes);

                    //电话接通率%
                    callTaskDetailTotalVo.setConnectedRate(Integer.parseInt(numberFormat.format(((float)connectedTimes/(float)progressTotal*100))));
                }
            }

            for(String key : paramMap.keySet()){
                if("sessionId".equals(key)|| "NULL".equals(paramMap.get(key).toString())||"null".equals(paramMap.get(key).toString())){
                    continue;
                }
                switch (key){
                    case "mainCallRinging":
                        if(!Boolean.valueOf(paramMap.get(key).toString())){
                            //电话拒绝次数
                            callTaskDetailTotalVo.setRejectTimes(callTaskDetailTotalVo.getRejectTimes()+1);
                        }
                        break;
                    case "recordTimeLength":
                        //被叫通话时长添加到总通话时长
                        callTaskDetailTotalVo.setCallTimeLength(callTaskDetailTotalVo.getCallTimeLength()+Integer.valueOf(paramMap.get(key).toString()));

                        //float callLength = Float.parseFloat(paramMap.get(key).toString());
                        //float callLengthRange = callLength/(float) 60;
                        float callLengthRange = Integer.parseInt(paramMap.get(key).toString());
                        if(callLengthRange>0&&callLengthRange<=20){//0-20秒的记录
                            int callTimeLengthATotal = callTaskDetailTotalVo.getCallTimeLengthATotal()+1;
                            callTaskDetailTotalVo.setCallTimeLengthATotal(callTimeLengthATotal);
                            callTaskDetailTotalVo.setCallTimeLengthA(Integer.parseInt(numberFormat.format(((float)callTimeLengthATotal/(float)connectedTimes*100))));

                            callTaskDetailTotalVo.setCallTimeLengthB(Integer.parseInt(numberFormat.format(((float)callTaskDetailTotalVo.getCallTimeLengthBTotal()/(float)connectedTimes*100))));
                            callTaskDetailTotalVo.setCallTimeLengthC(Integer.parseInt(numberFormat.format(((float)callTaskDetailTotalVo.getCallTimeLengthCTotal()/(float)connectedTimes*100))));
                            callTaskDetailTotalVo.setCallTimeLengthD(Integer.parseInt(numberFormat.format(((float)callTaskDetailTotalVo.getCallTimeLengthDTotal()/(float)connectedTimes*100))));
                        }else if(callLengthRange>20&&callLengthRange<=60){//20-60秒的记录
                            int callTimeLengthBTotal = callTaskDetailTotalVo.getCallTimeLengthBTotal()+1;
                            callTaskDetailTotalVo.setCallTimeLengthBTotal(callTimeLengthBTotal);
                            callTaskDetailTotalVo.setCallTimeLengthB(Integer.parseInt(numberFormat.format(((float)callTimeLengthBTotal/(float)connectedTimes*100))));

                            callTaskDetailTotalVo.setCallTimeLengthA(Integer.parseInt(numberFormat.format(((float)callTaskDetailTotalVo.getCallTimeLengthATotal()/(float)connectedTimes*100))));
                            callTaskDetailTotalVo.setCallTimeLengthC(Integer.parseInt(numberFormat.format(((float)callTaskDetailTotalVo.getCallTimeLengthCTotal()/(float)connectedTimes*100))));
                            callTaskDetailTotalVo.setCallTimeLengthD(Integer.parseInt(numberFormat.format(((float)callTaskDetailTotalVo.getCallTimeLengthDTotal()/(float)connectedTimes*100))));
                        }else if(callLengthRange>60&&callLengthRange<=300){//1-5分钟的记录
                            int callTimeLengthCTotal = callTaskDetailTotalVo.getCallTimeLengthCTotal()+1;
                            callTaskDetailTotalVo.setCallTimeLengthCTotal(callTimeLengthCTotal);
                            callTaskDetailTotalVo.setCallTimeLengthC(Integer.parseInt(numberFormat.format(((float)callTimeLengthCTotal/(float)connectedTimes*100))));

                            callTaskDetailTotalVo.setCallTimeLengthB(Integer.parseInt(numberFormat.format(((float)callTaskDetailTotalVo.getCallTimeLengthBTotal()/(float)connectedTimes*100))));
                            callTaskDetailTotalVo.setCallTimeLengthA(Integer.parseInt(numberFormat.format(((float)callTaskDetailTotalVo.getCallTimeLengthATotal()/(float)connectedTimes*100))));
                            callTaskDetailTotalVo.setCallTimeLengthD(Integer.parseInt(numberFormat.format(((float)callTaskDetailTotalVo.getCallTimeLengthDTotal()/(float)connectedTimes*100))));
                        }else if(callLengthRange>300){//5分钟以上
                            int callTimeLengthDTotal = callTaskDetailTotalVo.getCallTimeLengthDTotal()+1;
                            callTaskDetailTotalVo.setCallTimeLengthDTotal(callTimeLengthDTotal);
                            callTaskDetailTotalVo.setCallTimeLengthD(Integer.parseInt(numberFormat.format(((float)callTimeLengthDTotal/(float)connectedTimes*100))));

                            callTaskDetailTotalVo.setCallTimeLengthB(Integer.parseInt(numberFormat.format(((float)callTaskDetailTotalVo.getCallTimeLengthBTotal()/(float)connectedTimes*100))));
                            callTaskDetailTotalVo.setCallTimeLengthC(Integer.parseInt(numberFormat.format(((float)callTaskDetailTotalVo.getCallTimeLengthCTotal()/(float)connectedTimes*100))));
                            callTaskDetailTotalVo.setCallTimeLengthA(Integer.parseInt(numberFormat.format(((float)callTaskDetailTotalVo.getCallTimeLengthATotal()/(float)connectedTimes*100))));
                        }
                        break;
                    case "roundTimes" ://对话轮次
                        int roundTimes = Integer.valueOf(paramMap.get(key).toString());
                        if(roundTimes>=1&&roundTimes<=3){
                            int roundTimesATotal = callTaskDetailTotalVo.getRoundTimesATotal()+1;
                            callTaskDetailTotalVo.setRoundTimesATotal(roundTimesATotal);
                            callTaskDetailTotalVo.setRoundTimesA(Integer.parseInt(numberFormat.format(((float)roundTimesATotal/(float)connectedTimes*100))));

                            callTaskDetailTotalVo.setRoundTimesB(Integer.parseInt(numberFormat.format(((float)callTaskDetailTotalVo.getRoundTimesBTotal()/(float)connectedTimes*100))));
                            callTaskDetailTotalVo.setRoundTimesC(Integer.parseInt(numberFormat.format(((float)callTaskDetailTotalVo.getRoundTimesCTotal()/(float)connectedTimes*100))));
                            callTaskDetailTotalVo.setRoundTimesD(Integer.parseInt(numberFormat.format(((float)callTaskDetailTotalVo.getRoundTimesDTotal()/(float)connectedTimes*100))));
                        }else if(roundTimes>=4&&roundTimes<=6){
                            int roundTimesBTotal = callTaskDetailTotalVo.getRoundTimesBTotal()+1;
                            callTaskDetailTotalVo.setRoundTimesBTotal(roundTimesBTotal);
                            callTaskDetailTotalVo.setRoundTimesB(Integer.parseInt(numberFormat.format(((float)roundTimesBTotal/(float)connectedTimes*100))));

                            callTaskDetailTotalVo.setRoundTimesA(Integer.parseInt(numberFormat.format(((float)callTaskDetailTotalVo.getRoundTimesATotal()/(float)connectedTimes*100))));
                            callTaskDetailTotalVo.setRoundTimesC(Integer.parseInt(numberFormat.format(((float)callTaskDetailTotalVo.getRoundTimesCTotal()/(float)connectedTimes*100))));
                            callTaskDetailTotalVo.setRoundTimesD(Integer.parseInt(numberFormat.format(((float)callTaskDetailTotalVo.getRoundTimesDTotal()/(float)connectedTimes*100))));
                        }else if(roundTimes>=7&&roundTimes<=10){
                            int roundTimesCTotal = callTaskDetailTotalVo.getRoundTimesCTotal()+1;
                            callTaskDetailTotalVo.setRoundTimesCTotal(roundTimesCTotal);
                            callTaskDetailTotalVo.setRoundTimesC(Integer.parseInt(numberFormat.format(((float)roundTimesCTotal/(float)connectedTimes*100))));

                            callTaskDetailTotalVo.setRoundTimesA(Integer.parseInt(numberFormat.format(((float)callTaskDetailTotalVo.getRoundTimesATotal()/(float)connectedTimes*100))));
                            callTaskDetailTotalVo.setRoundTimesB(Integer.parseInt(numberFormat.format(((float)callTaskDetailTotalVo.getRoundTimesBTotal()/(float)connectedTimes*100))));
                            callTaskDetailTotalVo.setRoundTimesD(Integer.parseInt(numberFormat.format(((float)callTaskDetailTotalVo.getRoundTimesDTotal()/(float)connectedTimes*100))));
                        }else if(roundTimes>=11){
                            int roundTimesDTotal = callTaskDetailTotalVo.getRoundTimesDTotal()+1;
                            callTaskDetailTotalVo.setRoundTimesDTotal(roundTimesDTotal);
                            callTaskDetailTotalVo.setRoundTimesD(Integer.parseInt(numberFormat.format(((float)roundTimesDTotal/(float)connectedTimes*100))));

                            callTaskDetailTotalVo.setRoundTimesA(Integer.parseInt(numberFormat.format(((float)callTaskDetailTotalVo.getRoundTimesATotal()/(float)connectedTimes*100))));
                            callTaskDetailTotalVo.setRoundTimesB(Integer.parseInt(numberFormat.format(((float)callTaskDetailTotalVo.getRoundTimesBTotal()/(float)connectedTimes*100))));
                            callTaskDetailTotalVo.setRoundTimesC(Integer.parseInt(numberFormat.format(((float)callTaskDetailTotalVo.getRoundTimesCTotal()/(float)connectedTimes*100))));
                        }
                        break;
                    case "focusWords"://关键词统计
                        List<String> focusWords = (List<String>)paramMap.get(key);
                        Map<String,Integer> wordCount = callTaskDetailTotalVo.getWordCount();
                        if(wordCount==null){
                            wordCount = new HashMap<>();
                        }
                        if(StringTools.isNotempty(focusWords)){
                            for(String focusWord : focusWords){
                                if(wordCount.containsKey(focusWord)){
                                    wordCount.put(focusWord,wordCount.get(focusWord)+1);
                                }else{
                                    wordCount.put(focusWord,1);
                                }
                            }
                        }
                        callTaskDetailTotalVo.setWordCount(wordCount);
                        break;
                    case "customerNeedLevel"://客户意向等级
                        CustomerNeedLevel customerNeedLevel = (CustomerNeedLevel) paramMap.get(key);
                        if(customerNeedLevel.getValue().equals(CustomerNeedLevel.A.getValue())){
                            int levelATotal = callTaskDetailTotalVo.getLevelATotal()+1;
                            callTaskDetailTotalVo.setLevelATotal(levelATotal);
                            callTaskDetailTotalVo.setLevelA(Integer.parseInt(numberFormat.format(((float)levelATotal/(float)connectedTimes*100))));

                            callTaskDetailTotalVo.setLevelB(Integer.parseInt(numberFormat.format(((float)callTaskDetailTotalVo.getLevelBTotal()/(float)connectedTimes*100))));
                            callTaskDetailTotalVo.setLevelC(Integer.parseInt(numberFormat.format(((float)callTaskDetailTotalVo.getLevelCTotal()/(float)connectedTimes*100))));
                            callTaskDetailTotalVo.setLevelD(Integer.parseInt(numberFormat.format(((float)callTaskDetailTotalVo.getLevelDTotal()/(float)connectedTimes*100))));
                            callTaskDetailTotalVo.setLevelE(Integer.parseInt(numberFormat.format(((float)callTaskDetailTotalVo.getLevelETotal()/(float)connectedTimes*100))));
                            callTaskDetailTotalVo.setLevelF(Integer.parseInt(numberFormat.format(((float)callTaskDetailTotalVo.getLevelFTotal()/(float)connectedTimes*100))));
                        }else if(customerNeedLevel.getValue().equals(CustomerNeedLevel.B.getValue())){
                            int levelBTotal = callTaskDetailTotalVo.getLevelBTotal()+1;
                            callTaskDetailTotalVo.setLevelBTotal(levelBTotal);
                            callTaskDetailTotalVo.setLevelB(Integer.parseInt(numberFormat.format(((float)levelBTotal/(float)connectedTimes*100))));

                            callTaskDetailTotalVo.setLevelA(Integer.parseInt(numberFormat.format(((float)callTaskDetailTotalVo.getLevelATotal()/(float)connectedTimes*100))));
                            callTaskDetailTotalVo.setLevelC(Integer.parseInt(numberFormat.format(((float)callTaskDetailTotalVo.getLevelCTotal()/(float)connectedTimes*100))));
                            callTaskDetailTotalVo.setLevelD(Integer.parseInt(numberFormat.format(((float)callTaskDetailTotalVo.getLevelDTotal()/(float)connectedTimes*100))));
                            callTaskDetailTotalVo.setLevelE(Integer.parseInt(numberFormat.format(((float)callTaskDetailTotalVo.getLevelETotal()/(float)connectedTimes*100))));
                            callTaskDetailTotalVo.setLevelF(Integer.parseInt(numberFormat.format(((float)callTaskDetailTotalVo.getLevelFTotal()/(float)connectedTimes*100))));
                        }else if(customerNeedLevel.getValue().equals(CustomerNeedLevel.C.getValue())){
                            int levelCTotal = callTaskDetailTotalVo.getLevelCTotal()+1;
                            callTaskDetailTotalVo.setLevelCTotal(levelCTotal);
                            callTaskDetailTotalVo.setLevelC(Integer.parseInt(numberFormat.format(((float)levelCTotal/(float)connectedTimes*100))));

                            callTaskDetailTotalVo.setLevelA(Integer.parseInt(numberFormat.format(((float)callTaskDetailTotalVo.getLevelATotal()/(float)connectedTimes*100))));
                            callTaskDetailTotalVo.setLevelB(Integer.parseInt(numberFormat.format(((float)callTaskDetailTotalVo.getLevelBTotal()/(float)connectedTimes*100))));
                            callTaskDetailTotalVo.setLevelD(Integer.parseInt(numberFormat.format(((float)callTaskDetailTotalVo.getLevelDTotal()/(float)connectedTimes*100))));
                            callTaskDetailTotalVo.setLevelE(Integer.parseInt(numberFormat.format(((float)callTaskDetailTotalVo.getLevelETotal()/(float)connectedTimes*100))));
                            callTaskDetailTotalVo.setLevelF(Integer.parseInt(numberFormat.format(((float)callTaskDetailTotalVo.getLevelFTotal()/(float)connectedTimes*100))));
                        }else if(customerNeedLevel.getValue().equals(CustomerNeedLevel.D.getValue())){
                            int levelDTotal = callTaskDetailTotalVo.getLevelDTotal()+1;
                            callTaskDetailTotalVo.setLevelDTotal(levelDTotal);
                            callTaskDetailTotalVo.setLevelD(Integer.parseInt(numberFormat.format(((float)levelDTotal/(float)connectedTimes*100))));

                            callTaskDetailTotalVo.setLevelA(Integer.parseInt(numberFormat.format(((float)callTaskDetailTotalVo.getLevelATotal()/(float)connectedTimes*100))));
                            callTaskDetailTotalVo.setLevelB(Integer.parseInt(numberFormat.format(((float)callTaskDetailTotalVo.getLevelBTotal()/(float)connectedTimes*100))));
                            callTaskDetailTotalVo.setLevelC(Integer.parseInt(numberFormat.format(((float)callTaskDetailTotalVo.getLevelCTotal()/(float)connectedTimes*100))));
                            callTaskDetailTotalVo.setLevelE(Integer.parseInt(numberFormat.format(((float)callTaskDetailTotalVo.getLevelETotal()/(float)connectedTimes*100))));
                            callTaskDetailTotalVo.setLevelF(Integer.parseInt(numberFormat.format(((float)callTaskDetailTotalVo.getLevelFTotal()/(float)connectedTimes*100))));
                        }else if(customerNeedLevel.getValue().equals(CustomerNeedLevel.E.getValue())){
                            int levelETotal = callTaskDetailTotalVo.getLevelETotal()+1;
                            callTaskDetailTotalVo.setLevelETotal(levelETotal);
                            callTaskDetailTotalVo.setLevelE(Integer.parseInt(numberFormat.format(((float)levelETotal/(float)connectedTimes*100))));

                            callTaskDetailTotalVo.setLevelA(Integer.parseInt(numberFormat.format(((float)callTaskDetailTotalVo.getLevelATotal()/(float)connectedTimes*100))));
                            callTaskDetailTotalVo.setLevelB(Integer.parseInt(numberFormat.format(((float)callTaskDetailTotalVo.getLevelBTotal()/(float)connectedTimes*100))));
                            callTaskDetailTotalVo.setLevelC(Integer.parseInt(numberFormat.format(((float)callTaskDetailTotalVo.getLevelCTotal()/(float)connectedTimes*100))));
                            callTaskDetailTotalVo.setLevelD(Integer.parseInt(numberFormat.format(((float)callTaskDetailTotalVo.getLevelDTotal()/(float)connectedTimes*100))));
                            callTaskDetailTotalVo.setLevelF(Integer.parseInt(numberFormat.format(((float)callTaskDetailTotalVo.getLevelFTotal()/(float)connectedTimes*100))));
                        }else if(customerNeedLevel.getValue().equals(CustomerNeedLevel.F.getValue())){
                            int levelFTotal = callTaskDetailTotalVo.getLevelFTotal()+1;
                            callTaskDetailTotalVo.setLevelFTotal(levelFTotal);
                            callTaskDetailTotalVo.setLevelF(Integer.parseInt(numberFormat.format(((float)levelFTotal/(float)connectedTimes*100))));

                            callTaskDetailTotalVo.setLevelA(Integer.parseInt(numberFormat.format(((float)callTaskDetailTotalVo.getLevelATotal()/(float)connectedTimes*100))));
                            callTaskDetailTotalVo.setLevelB(Integer.parseInt(numberFormat.format(((float)callTaskDetailTotalVo.getLevelBTotal()/(float)connectedTimes*100))));
                            callTaskDetailTotalVo.setLevelC(Integer.parseInt(numberFormat.format(((float)callTaskDetailTotalVo.getLevelCTotal()/(float)connectedTimes*100))));
                            callTaskDetailTotalVo.setLevelD(Integer.parseInt(numberFormat.format(((float)callTaskDetailTotalVo.getLevelDTotal()/(float)connectedTimes*100))));
                            callTaskDetailTotalVo.setLevelE(Integer.parseInt(numberFormat.format(((float)callTaskDetailTotalVo.getLevelETotal()/(float)connectedTimes*100))));
                        }
                        break;
                    case "replayFrequency":
                        callTaskDetailTotalVo.setReplayFrequency(callTaskDetailTotalVo.getReplayFrequency()+Integer.parseInt(paramMap.get(key).toString()));
                        break;
                        default:break;
                }
            }
            System.out.println(JSON.toJSONString(callTaskDetailTotalVo));
            redisTemplate.opsForHash().put(RedisKey.CALL_TASK,paramMap.get("callTaskId").toString(),JSON.toJSONString(callTaskDetailTotalVo));
        }
    }
}
